<%--
  Created by IntelliJ IDEA.
  User: 31921
  Date: 2024/12/15
  Time: 22:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
pageEncoding="UTF-8" %>
<%@ page import="com.User,java.util.*" %>
<html>
    <head>
        <title>用户管理</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                background-color: #f4f4f4;
                margin: 0;
                padding: 0;
            }
            .header {
                background-color: #4cafa7;
                color: white;
                padding: 15px;
                text-align: center;
            }
            .container {
                padding: 20px;
            }
            table {
                width: 100%;
                border-collapse: collapse;
                margin-top: 20px;
            }
            table, th, td {
                border: 1px solid #ddd;
            }
            th, td {
                padding: 10px;
                text-align: left;
            }
            th {
                background-color: #f2f2f2;
            }
            .button {
                background-color: #afaa4c;
                color: white;
                padding: 10px 15px;
                text-decoration: none;
                margin-top: 10px;
                border-radius: 4px;
            }
            .button:hover {
                background-color: #a06045;
            }
            .search {
                margin-bottom: 20px;
            }
            .back-button {
                background-color: #4c89af;
                color: white;
                padding: 10px 15px;
                text-decoration: none;
                border-radius: 4px;
                margin-top: 20px;
                display: inline-block;
            }
            .back-button:hover {
                background-color: #a06045;
            }
        </style>
    </head>
    <body>
        <div class="header">
             <h1>用户管理</h1>
        </div>
        <div class="container">
            <%--返回界面--%>
            <a href="home.jsp" class="back-button">返回</a>

            <%--新增用户按钮--%>
            <a href="addUser.jsp" class="button">新增用户</a>

                <%--用户列表--%>
            <table>
                <thead>
                <tr>
                    <th>用户id</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>邮箱</th>
                </tr>
                </thead>
                <tbody>
                <%
                    List<User> users = (List<User>) request.getAttribute("users");
                    if (users != null) {
                        /*out.println("从后端拿到用户数据为：" + users.size());*/
                        for (User user : users) {
                %>
                <tr>
                    <td><%= user.getId() %></td>
                    <td><%= user.getUsername() %></td>
                    <td><%= user.getPassword() %></td>
                    <td><%= user.getEmail() %></td>
                    <td>
                        <a href="userManagement?action=edit&id=<%= user.getId()%>" class="button">编辑</a>
                        <a href="userManagement?action=delete&id=<%= user.getId()%>" class="button">删除</a>
                    </td>
                </tr>
                <%
                       }
                    }else {
                        out.println("没有获取到用户数据");
                       }
                %>
                </tbody>
            </table>
        </div>


    </body>
</html>
